﻿using System;
using System.Data;
using System.Reflection;
using System.Windows.Forms;
using DevExpress.XtraBars;
using QL_Truong_Hoc.DanhMuc;
using QL_Truong_Hoc.KhungDaoTao;
using QL_Truong_Hoc.TuyenSinh;

namespace QL_Truong_Hoc
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private Timer mobjTimer = null;

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                if (Program.gblnLoggedIn == true)
                { btnDangNhap.Caption = "Đăng xuất"; }
                else
                { btnDangNhap.Caption = "Đăng nhập"; }
                lblData.Caption ="Database - " + Program.NameDatabase;
                tmrClock.Start();

                //timer check connection
                mobjTimer = new Timer();
                mobjTimer.Interval = 30000;
                mobjTimer.Tick += mobjTimer_Tick;
                mobjTimer.Start();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        void mobjTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Program.gobjConn.State == ConnectionState.Closed)
                    Program.gobjConn.Open();
            }
            catch { }
        }

        private void btnKhoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmKhoa objForm = new frmKhoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void tmrClock_Tick(object sender, EventArgs e)
        {
            try
            {
                lblClock.Caption = "Ngày hôm nay - " + DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToLongTimeString();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnKhoaHoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmKhoaHoc objForm = new frmKhoaHoc();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmNghe objForm = new frmNghe();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnMon_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmMonHoc objForm = new frmMonHoc();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDonVi_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmDonVi objForm = new frmDonVi();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnCapBac_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmCapBac objForm = new frmCapBac();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnChucVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmChucVu objForm = new frmChucVu();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnUuTien_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmDoiTuongUuTien objForm = new frmDoiTuongUuTien();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnKhungCD_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                frmKhungDaoTao objKhung = new frmKhungDaoTao(clsEnum.FORM_MODE.VIEW, clsEnum.TRINH_DO_DAO_TAO.CAO_DANG);
                objKhung.MdiParent = this;
                objKhung.Show();
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnKhungTC_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                frmKhungDaoTao objKhung = new frmKhungDaoTao(clsEnum.FORM_MODE.VIEW, clsEnum.TRINH_DO_DAO_TAO.TRUNG_CAP);
                objKhung.MdiParent = this;
                objKhung.Show();
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnKhungSC_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                frmKhungDaoTao objKhung = new frmKhungDaoTao(clsEnum.FORM_MODE.VIEW, clsEnum.TRINH_DO_DAO_TAO.SO_CAP);
                objKhung.MdiParent = this;
                objKhung.Show();
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDsDuTuyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmDanhSachDuTuyen objForm = new frmDanhSachDuTuyen();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnAddHocSinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmHocSinhDangKy objForm = new frmHocSinhDangKy(clsEnum.FORM_MODE.ADD);
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void xOpenForm(Form frmOpen)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                //check
                foreach (Form form in Application.OpenForms)
                {
                    if (form.GetType() == frmOpen.GetType())
                    {
                        form.Activate();
                        return;
                    }
                }

                frmOpen.MdiParent = this;
                frmOpen.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally { Cursor.Current = Cursors.Default; }
        }

        private void btnLopNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                KhungDaoTao.frmLopHocNghe objForm = new KhungDaoTao.frmLopHocNghe();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void tmrConnection_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Program.gobjConn.State == System.Data.ConnectionState.Closed)
                {
                    clsCommon.fncOpenConnection();
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDanhSachLopNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmHocSinhLopNghe objForm = new HocTap.frmHocSinhLopNghe();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnKhungVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                KhungDaoTao.frmKhungVanHoa objForm = new KhungDaoTao.frmKhungVanHoa(clsEnum.FORM_MODE.VIEW);
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnLopVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                KhungDaoTao.frmLopHocVanHoa objForm = new KhungDaoTao.frmLopHocVanHoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDanhSachLopVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmHocSinhLopVanHoa objForm = new HocTap.frmHocSinhLopVanHoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnThongBaoNhapHoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                TuyenSinh.frmThongBaoNhapHoc objForm = new TuyenSinh.frmThongBaoNhapHoc();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnPhieuVaoLop_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                TuyenSinh.frmVietPhieuVaoLop objForm = new TuyenSinh.frmVietPhieuVaoLop();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDiemNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmQuanLyDiemNghe objForm = new HocTap.frmQuanLyDiemNghe();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDiemVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmQuanLyDiemVanHoa objForm = new HocTap.frmQuanLyDiemVanHoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnBaoCaoDanhSachLopNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intLopID;

                //hiển thị chọn lớp
                using (frmChonLopNghe frmChonLop = new frmChonLopNghe())
                {
                    frmChonLop.ShowDialog();
                    intLopID = frmChonLop.LopID;
                    if (intLopID <= 0) return;
                }

                Cursor.Current = Cursors.WaitCursor;

                Export.frmExportExcel objForm = new Export.frmExportExcel();
                if (!objForm.fncExportDanhSachLopNghe(intLopID)) return;
                objForm.MdiParent = this;
                objForm.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnBaoCaoDanhSachLopVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intLopID;

                //hiển thị chọn lớp
                using (frmChonLopVanHoa frmChonLop = new frmChonLopVanHoa())
                {
                    frmChonLop.ShowDialog();
                    intLopID = frmChonLop.LopID;
                    if (intLopID <= 0) return;
                }

                Cursor.Current = Cursors.WaitCursor;

                Export.frmExportExcel objForm = new Export.frmExportExcel();
                if (!objForm.fncExportDanhSachLopVanHoa(intLopID)) return;
                objForm.MdiParent = this;
                objForm.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnBaoCaoDiemVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intLopID;
                int intMonID;

                //hiển thị chọn lớp
                using (frmChonLopVanHoa frmChonLop = new frmChonLopVanHoa())
                {
                    frmChonLop.ShowDialog(this);
                    intLopID = frmChonLop.LopID;
                    if (intLopID <= 0) return;
                }

                //hiển thị chọn môn
                using (frmChonMonVanHoa frmChonMon = new frmChonMonVanHoa())
                {
                    frmChonMon.ShowDialog();
                    intMonID = frmChonMon.MonID;
                    if (intMonID <= 0) return;
                }

                Cursor.Current = Cursors.WaitCursor;

                Export.frmExportExcel objForm = new Export.frmExportExcel();
                if (!objForm.fncExportDiemMonVanHoa(intLopID, intMonID)) return;
                objForm.MdiParent = this;
                objForm.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnBaoCaoDiemVanHoa4Mon_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intLopID;

                //hiển thị chọn lớp
                using (frmChonLopVanHoa frmChonLop = new frmChonLopVanHoa())
                {
                    frmChonLop.ShowDialog(this);
                    intLopID = frmChonLop.LopID;
                    if (intLopID <= 0) return;
                }

                Cursor.Current = Cursors.WaitCursor;

                Export.frmExportExcel objForm = new Export.frmExportExcel();
                if (!objForm.fncExportDiemMonVanHoa4Mon(intLopID)) return;
                objForm.MdiParent = this;
                objForm.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnChuyenLopNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmChuyenLopNghe objForm = new HocTap.frmChuyenLopNghe();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnChuyenLopVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmChuyenLopVanHoa objForm = new HocTap.frmChuyenLopVanHoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnThiHetMon_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmDSThiHetMon objForm = new HocTap.frmDSThiHetMon();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnBaoCaoDiemNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intKdtID;
                int intLopID;
                int intMonID;
                string strLopTen = "";
                string strMonTen = "";

                //hiển thị chọn lớp
                using (frmChonLopNghe frmChonLop = new frmChonLopNghe())
                {
                    frmChonLop.ShowDialog(this);
                    intKdtID = frmChonLop.KhungDaoTaoID;
                    intLopID = frmChonLop.LopID;
                    strLopTen = frmChonLop.LopTen;
                    if (intLopID <= 0) return;
                }

                //hiển thị chọn môn
                using (frmChonMonNghe frmChonMon = new frmChonMonNghe(intKdtID))
                {
                    frmChonMon.ShowDialog();
                    intMonID = frmChonMon.MonID;
                    strMonTen = frmChonMon.MonTen;
                    if (intMonID <= 0) return;
                }

                Cursor.Current = Cursors.WaitCursor;

                Export.frmExportExcel objForm = new Export.frmExportExcel();
                if (!objForm.fncExportDiemMonNghe(intLopID, intMonID)) return;
                objForm.Text = string.Format("Bảng điểm lớp {0} môn {1}", strLopTen, strMonTen);
                objForm.MdiParent = this;
                objForm.Show();

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnThiTotNghiepNghe_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmDSThiTotNghiep objForm = new HocTap.frmDSThiTotNghiep();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnThiTotNghiepVanHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmDsThiTotNghiepVanHoa objForm = new HocTap.frmDsThiTotNghiepVanHoa();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!clsCommon.fncMsgConfirm("Bạn có chắc muốn thoát khỏi chương trình?")) return;
            this.Close();
        }

        private void btnDangNhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Program.gblnLoggedIn = false;
                xEnableControl(false);

                //đóng hết các cửa sổ đang mở.
                for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
                {
                    if (Application.OpenForms[i] == this) continue;
                    Application.OpenForms[i].Close();
                }

                using (frmLogin objLogin = new frmLogin())
                {
                    objLogin.ShowDialog();
                    if (objLogin.LoginSuccess)
                    {
                        Program.gblnLoggedIn = true;
                        xEnableControl(true);
                    }
                }

            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private bool xEnableControl(bool blnState)
        {
            bool blnResult = false;
            try
            {
                foreach (BarItem btnItem in MenuEtude.Manager.Items)
                {
                    btnItem.Enabled = blnState;
                }

                if (Program.gblnLoggedIn)
                { btnDangNhap.Caption = "Đăng xuất"; }
                else
                { btnDangNhap.Caption = "Đăng nhập"; }

                btnCapNhatPhienBan.Enabled = true;
                btnDangNhap.Enabled = true;
                btnThoat.Enabled = true;
                btnHuongDanSuDung.Enabled = true;

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        private void btnQuanLyNguoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                System.Collections.Generic.List<DTO.TDanhSachDuTuyenDTO> objHS = DAO.TDanhSachDuTuyenDAO.SelectWhere(Program.gobjDb, "NhapHoc = 1");

                DTO.THocSinhTongKetDTO objTK = new DTO.THocSinhTongKetDTO();

                Program.gobjTrans = Program.gobjConn.BeginTransaction();
                bool blnSuccess = true;

                try
                {
                    for (int i = 0; i <= objHS.Count - 1; i++)
                    {
                        objTK.HS_ID = objHS[i].HS_ID;
                        blnSuccess = blnSuccess && DAO.THocSinhTongKetDAO.Insert(Program.gobjDb, Program.gobjTrans, objTK);
                    }
                }
                catch { Program.gobjTrans.Rollback(); }
                finally
                {
                    if (blnSuccess) Program.gobjTrans.Commit();
                    else Program.gobjTrans.Rollback();
                }

                frmQuanLyNguoiDung objForm = new frmQuanLyNguoiDung();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!clsCommon.fncMsgConfirm("Bạn có chắc muốn thoát khỏi chương trình?"))
            {
                e.Cancel = true;
                return;
            }
            //this.Close();
        }

        private void btnTongKet_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                HocTap.frmTongKet objForm = new HocTap.frmTongKet();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btTools_ItemClick(object sender, ItemClickEventArgs e)
        {
            //try
            //{
            //    TuyenSinh.Form1 objForm = new TuyenSinh.Form1();
            //    xOpenForm(objForm);
            //}
            //catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }

        }

        private void btPhantich_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmPhanCum objForm = new frmPhanCum();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDanToc_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmDanToc objForm = new frmDanToc();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnDiaDanh_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                frmDiaDanh objForm = new frmDiaDanh();
                xOpenForm(objForm);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnExportDuLieuPhanCum_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!clsCommon.fncCheckRole(Program.glstRoles, "bao_cao"))
                {
                    return;
                }

                int intLopID;

                //hiển thị chọn lớp
                using (frmChonLopNghe frmChonLop = new frmChonLopNghe())
                {
                    frmChonLop.ShowDialog();
                    intLopID = frmChonLop.LopID;
                    if (intLopID <= 0) return;

                    Cursor.Current = Cursors.WaitCursor;
                
                    Export.frmExportExcel objForm = new Export.frmExportExcel();
                    if (!objForm.fncExportPhanCum(frmChonLop.KhoasTen, frmChonLop.NgheTen, frmChonLop.KhungDaoTaoID, frmChonLop.TrinhDoDaoTaoID, intLopID)) return;
                    objForm.MdiParent = this;
                    objForm.Show();                    
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally
            {
                if (objData != null) objData.Dispose();
                Cursor.Current = Cursors.Default;
            }
        }
    }
}